﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class system_reg_total : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
        }
        else
        {
            TEmployee.CheckUser(this);

            mytotal.Text = GetTotal();
        }
    }

    private string GetTotal()
    {
        string result = "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" style='BORDER-COLLAPSE: collapse' bordercolor=\"#cfdfff\" width=\"96%\" align=\"center\">";

        result += "<tr height=30>";
        result += "<td align=center style=\"background-color: #ffcc99;\">序号</td>";
        result += "<td style=\"background-color: #ffcc99;\">注册名</td>";
        result += "<td style=\"background-color: #ffcc99;\">邮件地址</td>";
        string sSql22 = "select infoid,infoname from t_sys_info2 where typeid='A01' order by orderby";
        TSqlDBReader oType = new TSqlDBReader(sSql22);
        while (oType.FDataReader.Read())
        {
            result+="<td align=center style=\"background-color: #ffcc99;\">"+oType.FDataReader.GetValue(1).ToString()+"</td>";
        }
        oType.Free();

        result += "<td style=\"background-color: #ffcc99;\">合计</td>";

        result += "</tr>";

        int iNum = 1;
        string sSql = "select uid,bigname,email from t_user where status=1 order by bigname";
        TSqlDBReader oUser = new TSqlDBReader(sSql);
        while (oUser.FDataReader.Read())
        {
            int totalline = 0;
            
            result += "<tr height=22>";
            result += "<td align=center>" + iNum.ToString() + "</td>";
            result += "<td><a href=\"listmans.aspx?uid=" + oUser.FDataReader.GetValue(0).ToString() + "\" target=_blank>" + oUser.FDataReader.GetValue(1).ToString() + "</a></td>";
            result += "<td>" + oUser.FDataReader.GetValue(2).ToString() + "</td>";
            
            string sSql2="select infoid from t_sys_info2 where typeid='A01' order by orderby";
            TSqlDBReader2 oUnitType=new TSqlDBReader2(sSql2);
            while(oUnitType.FDataReader.Read())
            {
                result += "<td align=right>";
                string iCount = "0";
                string sSql3 = "select count(*) from t_linkman where inman='" + oUser.FDataReader.GetValue(0).ToString() + "' and unittype='" + oUnitType.FDataReader.GetValue(0).ToString() + "'";
                TSqlDBReader3 oCount = new TSqlDBReader3(sSql3);
                if (oCount.FDataReader.Read())
                {
                    iCount = oCount.FDataReader.GetValue(0).ToString();

                    totalline += Convert.ToInt32(iCount);
                }
                oCount.Free();
                result += iCount+"</td>";
            
            }
            oUnitType.Free();

            iNum++;

            result += "<td align=right>" + totalline.ToString() + "</td>";

            result += "</tr>";
        }
        oUser.Free();

        result += totalman();
        
        result += "</table>";
        
        return result;
    }

    private string totalman()
    {
        string result = "<tr>";

        int total2 = 0;
        
        result += "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";

        string sSql = "select infoid from t_sys_info2 where typeid='A01' order by orderby";
        TSqlDBReader2 oUnitType = new TSqlDBReader2(sSql);
        while (oUnitType.FDataReader.Read())
        {
            result += "<td align=right>";
            string iCount = "0";
            string sSql3 = "select count(*) from t_linkman where unittype='" + oUnitType.FDataReader.GetValue(0).ToString() + "'";
            TSqlDBReader3 oCount = new TSqlDBReader3(sSql3);
            if (oCount.FDataReader.Read())
            {
                iCount = oCount.FDataReader.GetValue(0).ToString();

                total2 += Convert.ToInt32(iCount);
            }
            oCount.Free();
            result += iCount + "</td>";

        }
        oUnitType.Free();

        result += "<td align=right>" + total2.ToString() + "</td>";

        result += "</tr>";
        
        return result;
    }
}
